/*
 * Copyright (c) 2001-2006 Accenture LLC.
 * All Rights Reserved.
 *
 * This software is the confidential and proprietary information of
 * Accenture. ("Confidential Information"). You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Accenture.
 *
 * ACCENTURE MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE
 * SUITABILITY OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING
 * BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. ACCENTURE
 * SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A
 * RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
 * DERIVATIVES.
 */
package org.tigris.elfin;

import java.util.List;

import org.springframework.beans.factory.*;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.FileSystemResource;

/**
 * @author zhisen.huang
 * 
 */
public class SimpleProcessor {

	private static SimpleProcessor factory = null;

	protected BeanFactory beanFactory = null;

	protected Processor defaultProcessor = null;

	private SimpleProcessor() {
		defaultProcessor = new NullProcessor();
	}

	public static SimpleProcessor getInstance() {
		if (factory == null) {
			factory = new SimpleProcessor();
		}
		return factory;
	}

	public Double process(String name, List<Double> params) {
		Processor processor = null;
		beanFactory = new XmlBeanFactory(new FileSystemResource(
				"elfin-spring.xml"));
		try {
			processor = (Processor) beanFactory.getBean(name);
		} catch (Exception ex) {
			processor = defaultProcessor;
		}
		return processor.process(params);
	}

}
